import React from 'react'
import { actionCreators } from '../../store';
import { connect } from 'react-redux';
import {fromJS} from 'immutable';
import Star from '../Star'
import { DetailsWrap } from './style'
class DetailInfo extends React.Component {
    render() {
        // 获取数据
        const data = this.props.details;
        if (JSON.stringify(data) === "{}") {
            return ""
        } else {
            return (
                <DetailsWrap>
                    <div className="info-container clear-fix">
                        <span className="iconfont backIocn" onClick={() => {
                            window.history.back(-1);
                        }}>&#xe685;</span>
                        <div className="info-img-container float-left">
                            <img src={data.img} alt="1" />
                        </div>
                        <div className="info-content">
                            <h1>{data.title}</h1>
                            <div className="star-container">
                                {/* 引用 Star 组件 */}
                                <Star star={data.star} />
                                <span className="price">￥{data.price}</span>
                            </div>
                            <p className="sub-title">{data.subTitle}</p>
                        </div>
                    </div>
                    {/* 设置 innerHTML */}
                    <p dangerouslySetInnerHTML={{ __html: data.desc }} className="info-desc"></p>
                </DetailsWrap>
            )
        }
    }
    componentDidMount() {
        let id = this.props.id;
        this.props._getshopDetails(id)
    }
}
const mapStateToProps = (state, ownProps) => {
    state= fromJS(state);
    return {
        details: state.getIn(["shopDetails", "details"]).toJS(),
    };
};
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        _getshopDetails(id) {
            dispatch(actionCreators._getshopDetails(id))
        }
    };
};
export default connect(mapStateToProps, mapDispatchToProps)(DetailInfo);
